<template>
  <view class="fix-top-window">
  	<view class="uni-header">
  		<view class="uni-group hide-on-phone">
  			<view class="uni-title">{{$t('user.text.help')}}</view>
  			<view class="uni-sub-title"></view>
  		</view>
  		<view class="uni-group">
        <button class="uni-button" type="primary" size="mini"
        	@click="save">{{$t('common.button.save')}}</button>
  		</view>
  	</view>
  	<view class="uni-container">
      <vue-ueditor-wrap v-model="detail.content" :config="editorConfig" editor-id="editor-demo-01"></vue-ueditor-wrap>
  	</view>
  	<!-- #ifndef H5 -->
  	<fix-window />
  	<!-- #endif -->
    

  </view>
</template>

<script>

  
  export default {
    data(){
      return {
        detail: {
          content: '<h2>Hello</h2>'
        },
        editorConfig: {}
      }
    },
    computed:{
      db(){
        return uniCloud.database()
      }
    },
    created() {
      this.UEDITOR_HOME_URL = '/static/UEditor/';

      this.editorConfig = {
      	serverUrl: '', // 后端上传服务地址
      	UEDITOR_HOME_URL: this.UEDITOR_HOME_URL,
      	catchRemoteImageEnable: true, // 抓取远程图片
      	listiconpath: `${this.UEDITOR_HOME_URL}listicon/`,
      	initialFrameHeight :500,
        initialFrameWidth : 'auto'
      };
      this.db.collection('print-help').get().then(res=>{
        if(res.result.data.length) this.detail = res.result.data[0]
      })
      
      
    },
    methods:{
      save(){
        this.db.collection('print-help').doc(this.detail._id).update({content:this.detail.content}).then(res=>{
          uni.showToast({
            title: '保存成功',
          })
        }).catch(err=>{
          uni.showToast({
            title: '保存失败',
            icon: 'error'
          })
        })
      }
    }
  }
</script>

<style>

</style>
